#!/bin/bash

#目录
rm -rf lib/mingw
mkdir -p lib/mingw

#下载
if [ ! -f openssl-1.0.2k.tar.gz ]; then
	wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
fi
if [ ! -f zlib-1.2.11.tar.gz ]; then
	wget http://zlib.net/zlib-1.2.11.tar.gz
fi
if [ ! -f pcre-8.40.tar.gz ]; then
	wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
fi

tar -xzf openssl-1.0.2k.tar.gz
tar -xzf zlib-1.2.11.tar.gz
tar -xzf pcre-8.40.tar.gz

libDir=$(pwd)/lib/mingw

#编译
cd openssl-1.0.2k
patch -p1 < ../patch/openssl-1.0.2h.patch

./Configure mingw64 --prefix=$libDir/openssl-1.0.2k
make -j4
make install
cd ..
rm -fr openssl-1.0.2k

cd pcre-8.40
./configure --prefix=$libDir/pcre-8.40
make -j4
make install
cd ..
rm -fr pcre-8.40

cd zlib-1.2.11
make -f win32/Makefile.gcc -j4
tmpdir=$libDir/zlib-1.2.11/bin
mkdir -p $tmpdir
cp zlib1.dll $tmpdir

tmpdir=$libDir/zlib-1.2.11/include
mkdir -p $tmpdir
cp zlib.h $tmpdir
cp zconf.h $tmpdir

tmpdir=$libDir/zlib-1.2.11/lib
mkdir -p $tmpdir
cp *.a $tmpdir
cd ..
rm -fr zlib-1.2.11

#pacman -S mingw-w64-x86_64-openssl
